<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
    <title>APIErrors::ClassMethods</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <link rel="stylesheet" href="../../css/reset.css" type="text/css" media="screen" />
<link rel="stylesheet" href="../../css/main.css" type="text/css" media="screen" />
<link rel="stylesheet" href="../../css/github.css" type="text/css" media="screen" />
<script src="../../js/jquery-1.3.2.min.js" type="text/javascript" charset="utf-8"></script>
<script src="../../js/jquery-effect.js" type="text/javascript" charset="utf-8"></script>
<script src="../../js/main.js" type="text/javascript" charset="utf-8"></script>
<script src="../../js/highlight.pack.js" type="text/javascript" charset="utf-8"></script>

</head>

<body>
    <div class="banner">
        
        <h1>
            <span class="type">Module</span>
            APIErrors::ClassMethods
            
        </h1>
        <ul class="files">
            
            <li><a href="../../files/app/api/api_errors_rb.html">app/api/api_errors.rb</a></li>
            
        </ul>
    </div>
    <div id="bodyContent">
        <div id="content">
  


  


  
  


  


  
    <!-- Method ref -->
    <div class="sectiontitle">Methods</div>
    <dl class="methods">
      
        <dt>I</dt>
        <dd>
          <ul>
            
              
              <li>
                <a href="#method-i-include_errors">include_errors</a>
              </li>
            
          </ul>
        </dd>
      
    </dl>
  

  



  

    

    

    


    


    <!-- Methods -->
        
      <div class="sectiontitle">Instance Public methods</div>
      
        <div class="method">
          <div class="title method-title" id="method-i-include_errors">
            
              <b>include_errors</b>()
            
            <a href="../../classes/APIErrors/ClassMethods.html#method-i-include_errors" name="method-i-include_errors" class="permalink">Link</a>
          </div>

          
            <div class="description">
              
            </div>
          

          

          

          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source:
                <a href="javascript:toggleSource('method-i-include_errors_source')" id="l_method-i-include_errors_source">show</a>
                
              </p>
              <div id="method-i-include_errors_source" class="dyn-source">
                <pre><span class="ruby-comment"># File app/api/api_errors.rb, line 15</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">include_errors</span>

  <span class="ruby-identifier">rescue_from</span> <span class="ruby-value">:all</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">e</span><span class="ruby-operator">|</span>
    <span class="ruby-constant">Rails</span>.<span class="ruby-identifier">logger</span>.<span class="ruby-identifier">error</span> <span class="ruby-node">&quot;#{e.message}\n\n#{e.backtrace.join(&quot;\n&quot;)}&quot;</span>
    <span class="ruby-identifier">out_error</span>(<span class="ruby-identifier">code</span><span class="ruby-operator">:</span> <span class="ruby-number">500</span>, <span class="ruby-identifier">msg</span><span class="ruby-operator">:</span> <span class="ruby-identifier">e</span>.<span class="ruby-identifier">message</span>)
  <span class="ruby-keyword">end</span>

  <span class="ruby-comment">#rescue_from VerifyFail do |e|</span>
    <span class="ruby-comment">#out_error(code: 1001, msg: e.message || &quot;失败&quot;)</span>
  <span class="ruby-comment">#end</span>

  <span class="ruby-comment">#rescue_from NoVisitPermission do |e|</span>
    <span class="ruby-comment">#out_error(code: 1002, msg: &quot;无访问权限&quot;)</span>
  <span class="ruby-comment">#end</span>

  <span class="ruby-identifier">rescue_from</span> <span class="ruby-constant">AuthenticateFail</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">e</span><span class="ruby-operator">|</span>
    <span class="ruby-identifier">out_error</span>(<span class="ruby-identifier">code</span><span class="ruby-operator">:</span> <span class="ruby-number">401</span>, <span class="ruby-identifier">msg</span><span class="ruby-operator">:</span> <span class="ruby-string">&quot;没有访问权限，请重新登录&quot;</span>)
  <span class="ruby-keyword">end</span>

  <span class="ruby-comment">#rescue_from ActiveRecord::RecordNotFound do |e|</span>
    <span class="ruby-comment">#out_error(code: 1004, msg: &quot;没有找到相关数据&quot;)</span>
  <span class="ruby-comment">#end</span>

  <span class="ruby-comment">#rescue_from ActiveRecord::RecordInvalid do |e|</span>
    <span class="ruby-comment">#out_error(code: 1005, msg: e.message)</span>
  <span class="ruby-comment">#end</span>

  <span class="ruby-comment">#rescue_from Grape::Exceptions::ValidationErrors do |e|</span>
    <span class="ruby-comment">#out_error(code: 1006, msg: e.message || &quot;输入内容格式有误&quot;)</span>
  <span class="ruby-comment">#end</span>

  <span class="ruby-identifier">rescue_from</span> <span class="ruby-constant">NoGetAuthenticate</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">e</span><span class="ruby-operator">|</span>
    <span class="ruby-identifier">out_error</span>(<span class="ruby-identifier">code</span><span class="ruby-operator">:</span> <span class="ruby-number">401</span>, <span class="ruby-identifier">msg</span><span class="ruby-operator">:</span> <span class="ruby-string">&quot;没有在header中得到token参数&quot;</span>)
  <span class="ruby-keyword">end</span>


<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
                    </div>

    </div>
  </body>
</html>
